package hash.medium;


import java.util.*;

/**
 * 猜数字游戏
 */
public class BullsAndCows_299 {

    public String getHint(String secret, String guess) {

        int bulls = 0;
        int cows = 0;
        int[] s = new int[10], g = new int[10];
        for (int i = 0; i < secret.length(); i++) {
            int ch = secret.charAt(i) - '0', ch1 = guess.charAt(i) - '0';
            if (ch == ch1) {
                bulls++;
            } else {
                s[ch]++;
                g[ch1]++;
            }
        }
        for (int i = 0; i < 10; i++) {
            cows += Math.min(s[i], g[i]);
        }

        return bulls + "A" + cows + "B";
    }

    public static void main(String[] args) {
        BullsAndCows_299 bac = new BullsAndCows_299();
        System.out.println(bac.getHint("1123","0111"));
    }

}
